#include "fire.h"
#include "math.h"

/*Initialise une structure de type Fire*/
void Fire_Init(Fire* fire, Explosion* explosionArray, int explosionCount, float explosionDelay, float orientation, float trajectory, float velocity)
{
	Particle* particle = (Particle*) malloc(sizeof(Particle));
	Vector3f ori = {0,0,0};
	Vector3f str;
	Color c;

	Vector3f_InitFromAngle(&str,rad(orientation),rad(trajectory));
	Vector3f_Mul(&str,velocity,&str);
	Color_Init(&c,255,255,255,255);
	Particle_Init(particle,c,ori,str);
	fire->explosionArray = explosionArray;
	fire->explosionCount = explosionCount;
	fire->explosionDelay = explosionDelay;
	fire->orientation = orientation;
	fire->particle = particle;
	fire->trajectory = trajectory;
	fire->velocity = velocity;
}

void Fire_Update(Fire* fire, float elapsedTime)
{
	int i;
	Particle_Update(fire->particle,elapsedTime);
	fire->explosionDelay -= (int)(elapsedTime * 1000);
	if(fire->explosionDelay <= 0)
	{
		for(i = 0; i < fire->explosionCount; i++)
		{
			fire->explosionArray[i].haveExplosed = TRUE;
			Explosion_Update(&fire->explosionArray[i],elapsedTime);
		}
	}
}

void Fire_Draw(const Fire* fire, const Camera* camera)
{
	int i;
	Particle_Draw(fire->particle,camera);
	if(fire->explosionDelay <= 0)
	{
		for(i = 0; i < fire->explosionCount; i++)
			Explosion_Draw(&fire->explosionArray[i],camera);
	}
}

void Fire_setDelay(float pourcentage) {

}

/*
void Fire_getAlpha(Fire* fire, float distance, float height, float velocity) {
	float g = 9.81;
	float y;
	float d = fire->particle->position;

	y = -(1/2) * g * ((d*d)/(fire->velocity*fire->velocity*cos*cos(fire->trajectory)))+tan(fire->trajectory)*d;
}*/
/*
float Fire_getDistance(Fire* fire, float distance) {
	float d;
	float x = fire->particle->position.x;
	float z = fire->particle->position.z;
	
	d = sqrt((x*x)+(z*z))/2;
	return d;
}*/



